<%@ page import="java.util.jar.Attributes.Name"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="support.*,bean.*,java.util.*" %>
    
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>More degree</title>
<link href="main.css" rel="stylesheet" type="text/css">
</head>
<body>
<%
	// Get location from HTTP request
	Vector<Degree> degrees = (Vector<Degree>)session.getAttribute("degrees");
	Degree degree = null;
	if(degrees == null)
	{
		degrees = new Vector<Degree>();
		degree = new Degree();
		degrees.add(degree);
		session.setAttribute("degrees", degrees);
	}
	degree = degrees.lastElement();
	int discipline_id;
	String discipline = (String)request.getParameter("discipline");
	String month = (String)request.getParameter("month");
	String year = (String)request.getParameter("year");
	String gpa = (String)request.getParameter("gpa");
	String title = (String)request.getParameter("title");
	
	support s = new support();
	Vector disciplines = (Vector)application.getAttribute("disciplines");
	if(disciplines == null)
	{	
		String path = config.getServletContext().getRealPath("majors.txt");
		disciplines = s.getMajors(path);
		application.setAttribute("disciplines",disciplines);
	}
	
	if(discipline.equals("")) {
		discipline_id = Integer.valueOf((String)request.getParameter("discipline_id")); 
	}
	else {
		discipline_id = disciplines.size();
		disciplines.add(discipline);
	}
	degree.setDiscipline(discipline_id);
	degree.setMonth(month);
	if(!year.equals(""))
	{
		degree.setYear(Integer.valueOf(year));
	}
	if(!gpa.equals(""))
	{
		degree.setGPA(Float.valueOf(gpa));
	}
	degree.setTitle(title);
%>

<h1>Your degrees</h1>
<%
String location;
String university;
Vector universities = (Vector)application.getAttribute("universities");
if(universities == null)
{
	String path = config.getServletContext().getRealPath("universities.txt");
	universities = s.getUniversities(path);
	application.setAttribute("universities",universities);
}
for(int i = 0;i<degrees.size();i++)
{
	int loc_id = degrees.get(i).getLocation();
	int univ_id = degrees.get(i).getUniv();
	Vector loc_vec = (Vector) universities.get(loc_id);
	location = (String) loc_vec.get(0);
	university = (String) ((Vector) loc_vec.get(1)).get(univ_id);
	discipline = (String)disciplines.get(degrees.get(i).getDiscipline());
%>
	<em>Degree <%= i+1 %>:</em><br/>
	<b>Location:</b> <%= location %> <b>University:</b> <%= university %> <b>Major:</b> <%= discipline %> <br/>
	<b>Awarded Date:</b> <%= degrees.get(i).getMonth() %> / <%= degrees.get(i).getYear() %> <br/>
	<b>GPA:</b> <%= degrees.get(i).getGPA() %> <b>Title of degree:</b> <%= degrees.get(i).getTitle() %> <br/> 
	--- <br />
<%
}
%>
<form name="form1" method="post">
	<input type="submit" value = "Submit Next Degree" onclick="document.forms['form1'].action = 'degree_location.jsp'">
	<input type="submit" value = "Done" onclick="document.forms['form1'].action = 'specialization.jsp'">
</form>	
</body>
</html>